package model;

import java.util.List;

import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;

public abstract class ListTableModel<T> extends AbstractTableModel {

    private static final long serialVersionUID = -5919699970082391871L;

    private List<T> model;

    protected ListTableModel(List<T> data) {
        model = data;
    }

    public void append(T line) {
        model.add(line);
        fireTableRowsInserted(model.size(), model.size());
    }

    public void addAll(List<T> lines) {
        model.addAll(lines);
        fireTableChanged(new TableModelEvent(this));
    }

    public void clear() {
        model.clear();
        fireTableDataChanged();
    }

    public T getLine(int line) {
        return model.get(line);
    }

    public int getRowCount() {
        return model.size();
    }

    public abstract int getColumnCount();

    public abstract Object getValueAt(int rowIndex, int columnIndex);
}
